﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_checknopass : System.Web.UI.Page
{
    string  strSql, SupplyGoodsId;
    static string _stHspid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        SupplyGoodsId = SysFun.ToTrim(Request.QueryString["SupplyGoodsId"]);
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                Db db = new Db();
                System.Data.IDataReader dr;

                strSql = "select * from SupplyPlan_Goods where SupplyGoodsId=" + SupplyGoodsId;
                dr = db.DataReader(strSql);
                while (dr.Read())
                {
                    labProductName.Text = dr["productname"].ToString();
                    labOutlookc.Text = dr["outlookc"].ToString();
                    labMedicinemodel.Text = dr["medicinemodel"].ToString();
                    labProductCode.Text = dr["ProductCode"].ToString();
                     // txtGoodsId.Visible = false;
                    LabGoodsId.Text = dr["GoodsId"].ToString();
                    LabGoodsName.Text = dr["goodsname"].ToString();
                 //   LabFactor.Text = dr["Factor"].ToString();
                  //  LabPack.Text = dr["Pack"].ToString();
                    LabCompanyName_SC.Text = dr["CompanyName_SC"].ToString();
                  //  txtCompanyName_PS.Text = dr["CompanyName_PS"].ToString();
                    txtNopassExplain.Text = dr["NopassExplain"].ToString();
                    //txtLicence.Text = dr["Licence"].ToString();
                    //txtLicenceDate.Text = dr["LicenceDate"].ToString();
                    LabCompanyName_TB.Text = dr["CompanyName_TB"].ToString();
                    
                }
                dr.Close();
                dr.Dispose();
                db.Close();
                CHeckHospital(SupplyGoodsId);

            }
        }
    }
    protected void BtnConfirm_Click(object sender, EventArgs e)
    {
      
        Db db = new Db();
        strSql = "update SupplyPlan_Goods set IsUse='0',NopassExplain='" + txtNopassExplain.Text.ToString() + "'  where SupplyGoodsId=" + SupplyGoodsId;
        strSql += "  update HospitalPurchase set state ='2' where SupplyGoodsId=" + SupplyGoodsId;
        db.Command(strSql);
        db.Close();
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "SupplyPlan_Goods", strSql, "../Agency/checknopass.aspx");

        Response.Write("<script>alert('该挂网药品撤废成功！！！');window.opener.location.reload();window.close();</script>");
 
   }

    protected void CHeckHospital(string _SupplyGoodsId)
    {
        System.Data.IDataReader drn;
        Db dbn = new Db();
        string strNp = "select hospitalname,hspid from PurchaseTable where SupplyGoodsId=" + _SupplyGoodsId;
        dbn = new Db();
        drn = dbn.DataReader(strNp);
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        int k = 1, j = 0;
        string AreaName = "", _area = "已勾选该药品并选择该配送企业的医院";
        sb.Append("<table width='98%' cellspacing='0' border='1' cellpadding='3'>");
        while (drn.Read())
        {
            if (AreaName != _area)
            {
                AreaName = _area;
                if (j != 0)
                {

                    switch (k % 4)
                    {
                        case 0:
                            sb.Append("</tr>");
                            break;
                        case 3:
                            sb.Append("<td>&nbsp;</td></tr>");
                            break;
                        case 2:
                            sb.Append("<td>&nbsp; </td><td>&nbsp; </td></tr>");
                            break;
                        case 1:
                            sb.Append("<td>&nbsp; </td><td> &nbsp;</td><td> &nbsp;</td></tr>");
                            break;

                    }
                }
                j = 1;
                k = 1;
                sb.Append("<tr>");
                sb.Append("<td colspan=3 style='color: #ff0033'>" + _area + "</td>");
                sb.Append("</tr>");
                sb.Append("<tr>");
            }
            else
            {
                if (k % 4 == 0)
                {
                    j = 1;
                    k = 1;

                    sb.Append("</tr><tr>");
                }
            }
            sb.Append("<td>" + drn["hospitalname"].ToString() + "</td>");
            _stHspid += ',' + drn["hspid"].ToString();
            k++;

        }
        switch (k % 4)
        {
            case 0:
                sb.Append("</tr>");
                break;
            case 3:
                sb.Append("<td>&nbsp;</td></tr>");
                break;
            case 2:
                sb.Append("<td>&nbsp; </td><td>&nbsp; </td></tr>");
                break;
            case 1:
                sb.Append("<td>&nbsp; </td><td> &nbsp;</td><td> &nbsp;</td></tr>");
                break;

        }

        sb.Append("<table>");
        Label4.Text = sb.ToString();
        drn.Close();
        drn.Dispose();
        dbn.Close();
    }
}
